package com.nondo.dean.saprfc.controller.admin;


import com.netflix.hystrix.contrib.javanica.annotation.HystrixCommand;
import com.nondo.dean.common.annotation.ApiVersion;
import com.nondo.dean.common.web.View;
import com.nondo.dean.saprfc.common.Util;
import com.nondo.dean.saprfc.model.CustomerSalesReportBean;
import com.nondo.dean.saprfc.model.ProductBean;
import com.nondo.dean.saprfc.model.param.CustomerSalesReportParam;
import com.nondo.dean.saprfc.service.CustomerSalesReportService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.client.RestTemplate;

import java.util.List;

/**
 * @author xiaofan
 * @Description:
 * @throws
 * @date 2018-04-1211:13
 * @Version
 */
@RestController("apiAdminCustomerReport")
@RequestMapping("/{v}/admin/report")
public class CustomerReportController {

    @Autowired
    CustomerSalesReportService customerSalesReportService;

    @Autowired
    RestTemplate restTemplate;

    /**
     * 经销商销售排行榜
     * @return
     */
    @ApiVersion(1)
    @RequestMapping("/sales/list")
    @HystrixCommand(fallbackMethod = "ErrorFallback")
    public View<List<CustomerSalesReportBean>> getCustomerSalesList(@RequestBody CustomerSalesReportParam param){
        View<List<CustomerSalesReportBean>> view = new View<>(20000,"查询成功");
        if(param == null){
            param = new CustomerSalesReportParam();
        }
        List<CustomerSalesReportBean> list = customerSalesReportService.getSapCustomerSalesList(param,Util.SAP_CLIENT);
        view.setData(list);
        return view;

    }
    /**
     * 产品销售排行
     * @return
     */
    @ApiVersion(1)
    @RequestMapping("/product/sales/list")
    @HystrixCommand(fallbackMethod = "ErrorFallback")
    public View<List<ProductBean>> getHotProductList(@RequestBody CustomerSalesReportParam param){
        View<List<ProductBean>> view = new View<>(20000,"查询成功");
        if(param == null){
            param = new CustomerSalesReportParam();
        }
        List<ProductBean> productBeanList =  customerSalesReportService.getSapProductSalesList(param,Util.SAP_CLIENT);
        view.setData(productBeanList);
        return view;

    }
}
